﻿namespace HZY.Core.FreeRedis;

/// <summary>
///  redis 启动器
/// </summary>
public class CoreFreeRedisStartup : StartupModule<CoreFreeRedisStartup>
{
    [Value("ConnectionStrings:Redis")] private string ConnectionStringRedis { get; } = null!;

    /// <summary>
    /// 配置服务
    /// </summary>
    /// <param name="webApplicationBuilder"></param>
    public override void ConfigureServices(WebApplicationBuilder webApplicationBuilder)
    {
        if (string.IsNullOrWhiteSpace(ConnectionStringRedis))
        {
            throw new ArgumentNullException("ConnectionStrings:Redis 配置信息读取失败！");
        }

        webApplicationBuilder.Services.AddSingleton(typeof(RedisClient),
            serviceProvider => new RedisClient(ConnectionStringRedis));
    }

    /// <summary>
    /// 启动服务
    /// </summary>
    /// <param name="webApplication"></param>
    public override void Configure(WebApplication webApplication)
    {
    }
}